require("dotenv").config();
const env=require('./env')
const resolve = dir => path.join(__dirname, dir);
const target = process.env.APP_URL;
const externals = {
  vue: "Vue",
  "vue-router": "VueRouter",
  vuex: "Vuex",
  axios: "axios",
  echarts: "echarts",
  "element-ui": "ELEMENT"
};

const cdn = {
  css: ["https://cdn.jsdelivr.net/npm/element-ui/lib/theme-chalk/index.css"],
  js: [
    "https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js",
    "https://cdn.jsdelivr.net/npm/vue-router/dist/vue-router.min.js",
    "https://cdn.jsdelivr.net/npm/vuex/dist/vuex.min.js",
    "https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js",
    "https://cdn.jsdelivr.net/npm/element-ui/lib/index.js",
    "https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js",
    "https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js",
    "https://cdn.jsdelivr.net/npm/echarts/map/js/china.js",
    "https://cdn.jsdelivr.net/npm/echarts/map/js/world.js"
  ]
};

const devProxy = [`/api`, `/`]; // 代理
// 生成代理配置对象
const proxyObj = {};
devProxy.forEach((value, index) => {
  proxyObj[value] = {
    ws: false,
    target: target,
    // 开启代理：在本地会创建一个虚拟服务端，然后发送请求的数据，并同时接收请求的数据，这样服务端和服务端进行数据的交互就不会有跨域问题
    changeOrigin: true,
    pathRewrite: {
      [`^${value}`]: value
    }
  };
});
module.exports={
  mode: "universal",
  /*
   ** Headers of the page
   */
env:{},
  head: {
    title: process.env.npm_package_name || "",
    meta: [
      { charset: "utf-8" },
      { name: "viewport", content: "width=device-width, initial-scale=1" },
      {
        hid: "description",
        name: "description",
        content: process.env.npm_package_description || ""
      }
    ],
    link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }]
  },
  /*
   ** Customize the progress-bar color
   */
  loading: { color: "#fff" },
  /*
   ** Global CSS
   */
  server: {
    port: 8741 // default: 3000
    // host: '0.0.0.0' // default: localhost,
  },

  devtools: true,
  css: ["element-ui/lib/theme-chalk/index.css"],
  /*
   ** Plugins to load before mounting the App
   */
  plugins: ["@/plugins/element-ui"],
  /*
   ** Nuxt.js dev-modules
   */
  buildModules: [],
  buildDir: ".nuxt",
  /*
   ** Nuxt.js modules
   */
  modules: [
    // Doc: https://axios.nuxtjs.org/usage
    "@nuxtjs/axios",
    "@nuxtjs/proxy",
   [ "@nuxtjs/dotenv",{ filename: '.env' }]
  ],
  /*
   ** Axios module configuration
   ** See https://axios.nuxtjs.org/options
   */
  axios: {
    proxy: true
  },
  // proxy: proxyObj,
  /*
   ** Build configuration
   */
  build: {
    transpile: [/^element-ui/],
    /*
     ** You can extend webpack config here
     */
    extend(config, ctx) {},
    plugins: []
  }
};
